package com.gamota.mobi;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.gamota.mobi.util.CommonUtils;
import com.gamota.mobi.util.Utils;

public class DisplayCrashDialog extends Activity {

	private TextView error;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
		setContentView(R.layout.display_crash_activity);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
		String versionInfo=getString(R.string.version_app)+" "+Utils.getVersion(this)+" build "+Utils.getVersionCode(this)+"\n";
		Date now = new Date();
		String date = simpleDateFormat.format(now);
		error = (TextView) findViewById(R.id.error);
		error.setText(date+"\n"+versionInfo+"\n"+getIntent().getStringExtra("error"));
		Button sendCrash=(Button)findViewById(R.id.sendCrash);
		CommonUtils.writetoFile(error.getText().toString(), "Crashlog.log");
		sendCrash.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent email = new Intent(Intent.ACTION_SEND);
				email.putExtra(Intent.EXTRA_EMAIL, new String[]{"ngoc.kiemtraphanmem@gmail.com"});		  
				email.putExtra(Intent.EXTRA_SUBJECT, "[CrashLog]");
				email.putExtra(Intent.EXTRA_TEXT, error.getText().toString());
				email.setType("message/rfc822");
				startActivity(Intent.createChooser(email, "Choose an Email client :"));
			}
		});
	}
}
